﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Timesheet.Domain;
using Timesheet.Service;

namespace Timesheet.WebForm.Controls
{
    public partial class Menu : System.Web.UI.UserControl
    {
        private long userInfoId = 0;

        public IUserService UserService { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {

            //String isHave = "" + Session["HaveChooseCompany"];

            //if (isHave == "1")
            //{
            //    menuApp.Items[4].Visible = true;
            //}
            //else
            //    menuApp.Items[4].Visible = false;


            //long userInfoId = Int64.Parse("" + Session["UserId"]);

            //if (userInfoId == 1)
            //{
            //    menuApp.Items[2].Visible = true;
            //}
            //else
            //{
            //    menuApp.Items[2].Visible = false;
            //}

            userInfoId = Int64.Parse("" + Session["UserId"]);
            User userInfo = UserService.GetUserById(userInfoId);

            if (userInfo == null)
            {
                Response.Redirect("~/Account/login.aspx");
                return;
            }

            menuApp.Items[0].Visible = false;
            menuApp.Items[1].Visible = false;
            menuApp.Items[2].Visible = false;
            menuApp.Items[3].Visible = false;

            if (userInfo.TeamLead == true)
            {
                menuApp.Items[1].Visible = true;
            }

            if (userInfo.Coordinator == true)
            {
                menuApp.Items[0].Visible = true;
                menuApp.Items[1].Visible = true;
            }

            if (userInfo.Manager == true){
                menuApp.Items[0].Visible = true;
                menuApp.Items[1].Visible = true;
                menuApp.Items[2].Visible = true;
                menuApp.Items[3].Visible = true;
            }

            int count = 0;
            for (int i = 0; i < 4; i++)
            {
                if (menuApp.Items[i].Visible == false)
                    count++;
            }

            menuApp.Width = 500- (100 * count);

            menuApp.Items[5].Text = "Logout (" + userInfo.FullName + ")" ;
            //if (!IsPostBack)
            //{
            //    var url = Request.AppRelativeCurrentExecutionFilePath;
            //    foreach (DevExpress.Web.MenuItem menu in menuApp.Items)
            //    {

            //        if (menu.NavigateUrl.Equals(url))
            //        {
            //            menu.Selected = true;
            //            menu.ItemStyle.CssClass = "MenuItem";
            //        }

            //    }

            //}
        }
    }
}

